package aad.storyboard.model;

import java.util.ArrayList;

import aad.storyboard.controller.GUIComposer;
import aad.storyboard.view.GraphicView;

public class ActionDownHelper implements DragDropHelpCommand{
	
	private int X;
	private int Y;
	private GraphicView view;
	
	public ActionDownHelper()
	{
		view=(GraphicView) GUIComposer.getInstance().getGraphicalView();
	}

	@Override
	public void help() {		
        
		Integer key2 = new Integer(AnimationProvider.EVENT_DRAG);
		ArrayList<Animation> dragAnimations = AnimationProvider.getInstance().getOnEventAnimations().get(key2);
        
		for(Animation a : dragAnimations){
			int i=0;
			for(Image img : a.getImages()){	
    	
			
    		// check if inside the bounds of the image(circle)
    		// get the center for the image
    		int centerX = img.getPosX() + 25;
    		int centerY = img.getPosY() + 25;
    		
    		// calculate the radius from the touch to the center of the img
    		double radCircle  = Math.sqrt( (double) (((centerX-X)*(centerX-X)) + (centerY-Y)*(centerY-Y)));
    		
    		// if the radius is smaller then 23 (radius of a ball is 22), then it must be on the ball
    		if (radCircle < 23){
    			view.setDraggedImage(img);
    			System.out.println("DraggedImage set");
                break;
    		}
    		i++;
    		
			}
		}
		
	}

	@Override
	public void setX(int x) {
		X=x;
		
	}

	@Override
	public void setY(int y) {
		Y=y;
		
	}

}
